﻿#include "StdAfx.h"


#include "qpidl.h"


namespace micro
{
namespace shell
{



QArchive& operator<<( QArchive& ar,  const QPidl& pidl )
{

    UINT wLen = pidl.GetByteSize();
    ar<<wLen;
    if ( wLen )
        ar.Write( pidl.GetData(), wLen );
        
    return ar;
}



QArchive& operator>>( QArchive& ar, QPidl& pidl )
{
    UINT wLen = 0;
    ar >> wLen;
    LPITEMIDLIST mp = nullptr;
    
    if ( wLen  )
    {
        mp = ( LPITEMIDLIST ) CoTaskMemAlloc ( wLen );
        size_t sz = ar.Read( ( LPVOID )  mp , wLen );
        if ( !sz )
        {
            ::CoTaskMemFree( mp );
            mp = nullptr;
        }
    }
    else
    {
        mp = nullptr;
    }
    
    pidl = mp;
    return ar;
}

//permite MyPath + QPidl
QPidl  operator +( const QPidl& pidl1, const QPidl& pidl2 )
{
    QPidl pidl( pidl1 );
    pidl.Append( pidl2 );
    return pidl;
}


}
}